package a66weding.com.jiehuntong.dao.db.taskpic;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * Created by admin on 2016/8/20.
 */
public class MyTaskPictrueDao {

   private MyTaskPictureOpenHelper helper;

    public MyTaskPictrueDao(Context context){
        helper = new MyTaskPictureOpenHelper(context);
    }

    /**
     *
     * @param name
     * @param picture
     * @return
     */
    public long add(String name, String picture) {
        SQLiteDatabase db = helper.getWritableDatabase();
        // 其实就是一个map集合
        ContentValues values = new ContentValues();
        values.put("name", name);
        values.put("pictrue",picture );
        long result = db.insert("mytaskpicture", null, values);
        db.close();
        return result;
    }

    /**
     * 更新数据;
     */

    public int  update(String name, String pictrue) {
        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("pictrue",pictrue);
        int result  =db.update("mytaskpicture", values, "name=?", new String[] { name });
        db.close();
        return result;
    }

    /**
     * 查询
     */
    public String  find(String name){
       String  result = "" ;
        SQLiteDatabase db = helper.getReadableDatabase();
        Cursor cursor =	db.rawQuery("select * from mytaskpicture where name=?", new String[]{name});
        if(cursor.moveToNext()){
            result = cursor.getColumnName(1);
        }
        cursor.close();
        db.close();
        return result;
    }
}
